from django.contrib import admin
from .models import Article, Category,Comment


class PostAdmin(admin.ModelAdmin):
    list_display = ('title', 'content', 'create_time', 'author', 'update_time', 'excerpt', 'views')
    list_per_page = 8
    search_fields = ['title', 'content']
    list_display_links = ('title',)
    list_filter = ('create_time',)

    def category_cname(self, obj):
        return obj.category.cname if obj.category else None

    category_cname.short_description = '分类名称'  # 设置列标题


admin.site.register(Article, PostAdmin)


class CategoryAdmin(admin.ModelAdmin):
    list_display = ('id', 'cname')
    search_fields = ('cname',)

# class userAdmin(admin.ModelAdmin):
#     list_display = ('id', 'name', 'password')
#     search_fields = ('name',)
admin.site.register(Category, CategoryAdmin)
# admin.site.register(user)
admin.site.register(Comment)